<template>
	<!-- 新增 出库申请单 -->
	<view>
		<view class="card-wrapper">
			<!-- 主表 -->
			<view class="radius shadow shadow-lg bg-white padding-sm light bg-blue">
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">集团:</view>
					<view class="basis-xl text-black solid-bottom position-r"
						:class="activeLineIndex == 1 ? 'solid-bottom-blue' :'' ">
						<input class="wc-input" type="text" disabled v-model="mainOrder.GROUPNAME"
							placeholder="可选择集团" />
					</view>
				</view>
				<view class="flex flex-wrap margin-top" @tap="activeIndexM(2,'BA_ORGANIZE')">
					<view class="basis-xs">组织:</view>
					<view class="basis-xl text-black solid-bottom position-r"
						:class="activeLineIndex == 2 ? 'solid-bottom-blue' :'' ">
						<input class="wc-input" name="STORENAME" type="text" disabled v-model="mainOrder.ORGNAME"
							placeholder="可选择组织" />
						<view class="basis-xs text-right position-a down-arrow-btn">
							<text class="cuIcon-triangledownfill text-xxl text-bold"
								:class="activeLineIndex == 2 ? 'text-blue' :'' "></text>
						</view>
					</view>
				</view>
				<view class="flex flex-wrap margin-top" @tap="activeIndexM(0,'BA_DEPARTMENT')">
					<view class="basis-xs">部门:</view>
					<view class="basis-xl text-black solid-bottom position-r">
						<input class="wc-input" disabled name="STORENAME" type="text" placeholder="可选择部门"
							v-model="mainOrder.DEPTNAME" />
						<view class="basis-xs text-right position-a down-arrow-btn">
							<text class="cuIcon-triangledownfill text-xxl text-bold"
								:class="activeLineIndex == 3 ? 'text-blue' :'' "></text>
						</view>
					</view>
				</view>

				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">申请人:</view>
					<view class="basis-xl text-black solid-bottom position-r"
						:class="activeLineIndex == 5 ? 'solid-bottom-blue' :'' ">
						<input class="wc-input width60" disabled name="STORENAME" type="text"
							v-model="mainOrder.APPLYER" placeholder="请选择申请人" />
					</view>
				</view>

				<view class="flex flex-wrap margin-top">
					<view class="basis-xs ">
						出库类型<span class="text-red">*</span>
					</view>
					<view class="basis-xl solid-bottom  text-black">
						<picker @change="bindPickerChange($event,'1')" :value="outTypeIndex" :range="outType"
							:range-key="'ItemName'" class="picker-wrap">
							<view> {{ $utils.getExNumName(outType,mainOrder.OUTTYPE) || '请选择' }} </view>
							<text class="dicon diconxiangxiazhankai position-a down-arrow"></text>
						</picker>
					</view>
				</view>

				<view class="flex flex-wrap margin-top" v-if="mainOrder.OUTTYPE ==1 || mainOrder.OUTTYPE == 2  ">
					<view class="basis-xs">
						所属产品<span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexPRO('pp')">
						<input class="wc-input " disabled type="text" :value="mainOrder.PRODUCTNAME"
							placeholder="请选择" />
						<view class="basis-xs text-right position-a down-arrow-btn ">
							<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
						</view>
					</view>
				</view>

				<template v-if="USERZT == 'NXZNCC'">


					<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
						<view class="basis-xs">
							在建工程<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(1,'在建工程')">
							<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.ZJGCNAME"
								placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>

					<view class="flex flex-wrap margin-top"
						v-if="mainOrder.OUTTYPE ==1 || mainOrder.OUTTYPE == 2 || mainOrder.OUTTYPE ==5 ">
						<view class="basis-xs">
							研发工程<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(2,'研发工程')">
							<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.YFGCNAME"
								placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>

					<!-- <view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
					<view class="basis-xs ">
						是否资产<span class="text-red">*</span>
					</view>
					<view class="basis-xl solid-bottom  text-black radio-wrap">
						<radio-group @change="radioChange">
							<label class="radio">
								<radio value="1"  />是
							</label>
							<label class="radio">
								<radio value="0" checked="true" />否
							</label>
						</radio-group>
					</view>
				</view>

				<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
					<view class="basis-xs">
						资产<span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(6,'资产')">
						<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.MEANSNAME"
							placeholder="请选择" />
						<view class="basis-xs text-right position-a down-arrow-btn ">
							<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
						</view>
					</view>
				</view>

				<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
					<view class="basis-xs">
						维修日期<span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black solid-bottom position-r" @click="dateEvent('NEXTPAIRDATE','M')">
						{{ mainOrder.NEXTPAIRDATE }}
					</view>
				</view> -->

					<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
						<view class="basis-xs">
							单车核算<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(3,'单车核算')">
							<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.DCHSNAME"
								placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>

					<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
						<view class="basis-xs">
							核算分类<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(4,'核算分类')">
							<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.HSFLNAME"
								placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>

				</template>


				<view class="flex flex-wrap margin-top"
					v-if="outType,mainOrder.OUTTYPE !=3 ||  outType,mainOrder.OUTTYPE !=4">
					<view class="basis-xs">
						业务类型<span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(5,'业务类型')">
						<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.YWLXNAME"
							placeholder="请选择" />
						<view class="basis-xs text-right position-a down-arrow-btn ">
							<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
						</view>
					</view>
				</view>

				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">备注:</view>
					<view class="basis-xl text-black solid-bottom" :class="isActiveNote? 'solid-bottom-blue' :'' ">
						<input @focus="activeNote" @blur="getNote" class="wc-input" type="text"
							v-model="mainOrder.VMEMO" placeholder="请输入备注" />
					</view>
				</view>
			</view>
			<!-- 物资子表 -->
			<view class="radius shadow shadow-lg bg-white padding-sm margin-top sub-table"
				v-for="(item,index) in checkData" :key="index">
				<view class="text-red delete-cicon" @click="removeEvent(index)">
					<i class="dicon">&#xe937;</i>
				</view>
				<view class="flex flex-wrap">
					<view class="basis-xs">物资单号</view>
					<view class="basis-xl text-black">
						{{ item.PK_MATERIAL || '' }}
					</view>
				</view>
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">名称规格</view>
					<view class="basis-xl text-black">{{ item.MATERIALNAME }}/{{ item.MATSPEC || '' }}</view>
				</view>

				<view class="flex flex-wrap margin-top" v-for="(itemS,indexS) in mapSattionName(item.VBDEF18)">
					<view class="basis-xs">{{ indexS+1 }}号货位</view>
					<view class="basis-xl text-black">{{ itemS.STATIONNAME || '' }}/{{ itemS.KCNUM }} {{ item.UNIT }}
					</view>
				</view>

				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">库存总量</view>
					<view class="basis-xl text-black">{{ item.TOTALNUM || '' }} {{ item.UNIT || '' }}</view>
				</view>


				<view class="flex flex-wrap margin-top line-height-30">
					<view class="basis-xs">申请数量<span class="text-red">*</span></view>
					<view class="basis-xl solid-bottom sub-table-input">
						<input class="wc-input" v-model="item.NNUM" type="number" placeholder="请输入出货量" />
					</view>
				</view>

				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">生产日期</view>
					<view class="basis-xl text-black solid-bottom" @click="dateEvent('FACTORYDATE',index)">
						{{ item.FACTORYDATE || item.INSTOCKDATE }}
					</view>
				</view>
				
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						设备信息
					</view>
					<view class="basis-xl text-black position-r solid-bottom" :class="isActiveStore? 'solid-bottom-blue' :'' ">
						<input class="wc-input" style="width: 60%;" name="EQUIPNAME" type="text" :value="item.EQUIPNAME" placeholder="请选择"
						 @tap="activeIndexM(index,'EQBOM',true)" disabled />
						<view class="basis-xs text-right position-a scan-btn" @tap="handelScan(index)">
							<text class="cuIcon-scan text-xxl text-bold"></text>
						</view>
					</view>
				</view>



				<!-- 子表维护是否资产 -->
				<view class="" v-if="mainOrder.OUTTYPE ==5">
					<view class="flex flex-wrap margin-top line-height-30 ">
						<view class="basis-xs ">
							是否资产<span class="text-red">*</span>
						</view>
						<view class="basis-xl solid-bottom  text-black radio-wrap">
							<radio-group @change="radioChange($event, index)">
								<label class="radio">
									<radio value="1" :checked="item.ISMEANS==1" />是
								</label>
								<label class="radio">
									<radio value="0" :checked="item.ISMEANS==0" />否
								</label>
							</radio-group>
						</view>
					</view>
					<view class="flex flex-wrap margin-top line-height-30 ">
						<view class="basis-xs">
							资产<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(6,'资产' , index)">
							<input class="wc-input " disabled name="STORENAME" type="text" :value="item.MEANSNAME"
								placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>
					<view class="flex flex-wrap margin-top line-height-30 ">
						<view class="basis-xs">
							维修日期<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r"
							@click="dateEvent('NEXTPAIRDATE', index )">
							{{ item.NEXTPAIRDATE }}
						</view>
					</view>
				</view>

			</view>

			<view class>
				<button class="cu-btn block bg-blue margin-tb-sm lg" @click="submit">
					提交
				</button>
			</view>
		</view>

		<w-picker mode="dateTime" startYear="2000" endYear="2050" step="1" :defaultVal="[1,1,1,1,2,5]" :current="true"
			@confirm="onConfirm" ref="dateTime" themeColor="#f00"></w-picker>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex";
	import wPicker from "@/components/w-picker/w-picker.vue";
	import api from "@/common/api.js";
	import utils from "@/common/util.js";
	// var graceChecker = require("../../common/graceChecker.js");
	let query = {
		category: "ST_INAPPLY",
		page: 1,
		rows: "50",
		sidx: "",
		sord: "",
		queryJson: {},
		userId: "",
		account: "admin"
	};
	let _self, dateTimekey, activeIndex, VMEMO, BILLFROM, activeType;
	export default {
		computed: mapState(["userInfo", "baseUrl", "materUse", "checkData", 'outType']),
		data() {
			return {
				outTypeIndex: 0,
				mainOrder: {
					PK_GROUP: "",
					GROUPNAME: "",
					PK_ORG: "",
					ORGNAME: "",
					PK_DEPT: "",
					DEPTNAME: "",
					PK_APPLYER: "",
					APPLYER: "",
					PK_SUPPLY: "",
					SUPPLYNAME: "",
					PK_STORE: "",
					STORENAME: "",
					// "BILLFROM": 0,
					VMEMO: "",
					userId: "",
					account: "",
					OUTTYPE: '1',
					OUTTYPENAME: '生产出库',
					PK_PRODUCT: '',
					PRODUCTNAME: '',
					PK_ZJGC: '',
					ZJGCNAME: '',
					PK_YFGC: '',
					YFGCNAME: '',
					PK_DCHS: '',
					DCHSNAME: '',
					PK_HSFL: '',
					HSFLNAME: '',
					YWLXNAME: '',
					PK_YWLX: '',
					ISMEANS: 0, // 是否资产
					PK_MEANS: '', // 资产编号
					MEANSNAME: '', // 资产名称
					NEXTPAIRDATE: '', // 资产维修日期
				},
				planList: [],
				isActiveNote: false,
				isActiveStore: false,
				mid: "",
				today: utils.getToDay(),
				dateTimekey: "",
				activeIndex: '',
				activeLineIndex: 0,
				label01: "单号", // 主表的第一个label BD_MATERIAL,
				USERZT: '',
			};
		},
		components: {
			wPicker
		},
		onLoad(p) {
			_self = this;
			this.initSetData();
			this.setOnceEvent()
			// let abc = JSON.parse(decodeURIComponent(p.data));
			let abc = this.checkData;
			// this.planList = this.checkData
			this.USERZT = this.userInfo.USERZT
		},
		onShow() {
			// console.log(this.checkData);
			uni.$on("getSelectItem", function(data) {
				// console.log(666, activeType,_self.activeLineIndex , data);
				switch (activeType) {
					case "GROUP":
						_self.mainOrder.GROUPNAME = data.FullName;
						_self.mainOrder.PK_GROUP = data.OrganizeId;
						break;
					case "BA_ORGANIZE":
						_self.mainOrder.ORGNAME = data.FullName;
						_self.mainOrder.PK_ORG = data.OrganizeId;
						break;
					case "BA_DEPARTMENT":
						_self.mainOrder.DEPTNAME = data.FullName;
						_self.mainOrder.PK_DEPT = data.OrganizeId;
						break;
					case "BD_SUPPLIER":
						_self.mainOrder.SUPPLYNAME = data.VNAME;
						_self.mainOrder.PK_SUPPLY = data.BILLNO;
						break;
					case "BA_USER":
						_self.mainOrder.APPLYER = data.RealName;
						_self.mainOrder.PK_APPLYER = data.UserId;
						break;
					case "BD_STORE": // 仓库
						if (_self.activeSub) {
							_self.planList[_self.activeLineIndex].PK_STORE = data.BILLNO;
							_self.planList[_self.activeLineIndex].STORENAME = data.VNAME;
						} else {
							_self.mainOrder.PK_STORE = data.BILLNO;
							_self.mainOrder.STORENAME = data.VNAME;
						}
						break;
					case "BD_RACK": // 货位
						if (_self.activeSub) {
							_self.planList[_self.activeLineIndex].STATIONNAME = data.VNAME;
							_self.planList[_self.activeLineIndex].PK_STATION = data.BILLNO;
						}
						break;
					case "EQBOM": // 设备
						_self.checkData[_self.activeLineIndex].EQUIPNAME = data.EQBOMNAME;
						_self.checkData[_self.activeLineIndex].PK_EQUIP = data.PK_EM_EQBOM;
						break;
					default:
						break;
				}
			});
		},
		onNavigationBarButtonTap(e) {
			e.index == 0 ? this.addItem() : _self.openScanMater();
			// this.addItem();
		},
		onUnload() {
			uni.$off("getSelectItem", function(data) {});
		},
		methods: {
			...mapMutations(["deleteCheckData", "PushCheckData", "setCheckData"]),
			// 初始化赋值
			initSetData() {
				query.userId = _self.userInfo.UserId;
				query.account = _self.userInfo.Account;
				_self.mainOrder.GROUPNAME = _self.userInfo.GROUPNAME || "";
				_self.mainOrder.PK_GROUP = _self.userInfo.PK_GROUP;
				_self.mainOrder.ORGNAME = _self.userInfo.ORGNAME;
				_self.mainOrder.PK_ORG = _self.userInfo.ORGANIZEID;
				_self.mainOrder.DEPTNAME = _self.userInfo.DEPTNAME;
				_self.mainOrder.PK_DEPT = _self.userInfo.DEPARTMENTID;
				_self.mainOrder.APPLYER = _self.userInfo.REALNAME;
				_self.mainOrder.PK_APPLYER = _self.userInfo.UserId;
				_self.mainOrder.userId = _self.userInfo.UserId;
				_self.mainOrder.account = _self.userInfo.Account;
				_self.mainOrder.OUTTYPE = 1
				_self.mainOrder.OUTTYPENAME = '生产出库'
			},

			setOnceEvent() {
				uni.$on('getSelectItemPro', res => {
					this.mainOrder.PK_PRODUCT = res.VCODE
					this.mainOrder.PRODUCTNAME = res.VNAME
				})
				uni.$on('getSelectItemGS', res => {
					switch (res.TYPE) {
						case '1':
							this.mainOrder.PK_ZJGC = res.BILLNO
							this.mainOrder.ZJGCNAME = res.VNAME
							break;
						case '2':
							this.mainOrder.PK_YFGC = res.BILLNO
							this.mainOrder.YFGCNAME = res.VNAME
							break;
						case '3':
							this.mainOrder.PK_DCHS = res.BILLNO
							this.mainOrder.DCHSNAME = res.VNAME
							break;
						case '4':
							this.mainOrder.PK_HSFL = res.BILLNO
							this.mainOrder.HSFLNAME = res.VNAME
							break;
						case '5':
							this.mainOrder.PK_YWLX = res.BILLNO
							this.mainOrder.YWLXNAME = res.VNAME
							break;
						case '6':
							_self.checkData[activeIndex].PK_MEANS = res.ZCBH
							_self.checkData[activeIndex].MEANSNAME = res.ZCMC
							break;
					}
				})
			},


			bindPickerChange(e, i, t) {
				let val = e.target.value;
				if (t == 2) {
					_self.activeIndex = i;
					this.checkData[_self.activeIndex].myindex01 = val
					this.checkData[_self.activeIndex].PURPOSE = _self.materUse[val].ItemValue
					this.checkData[_self.activeIndex].MATERIALUSE = _self.materUse[val].ItemValue
				} else {
					_self.outTypeIndex = val
					_self.mainOrder.OUTTYPE = _self.outType[val].ItemValue
					_self.mainOrder.OUTTYPENAME = _self.outType[val].ItemName

					_self.mainOrder.PK_PRODUCT = ''
					_self.mainOrder.PRODUCTNAME = ''
					_self.mainOrder.PK_ZJGC = ''
					_self.mainOrder.ZJGCNAME = ''
					_self.mainOrder.PK_YFGC = ''
					_self.mainOrder.YFGCNAME = ''
					_self.mainOrder.PK_DCHS = ''
					_self.mainOrder.DCHSNAME = ''
					_self.mainOrder.PK_HSFL = ''
					_self.mainOrder.HSFLNAME = ''
					_self.mainOrder.YWLXNAME = ''
					_self.mainOrder.PK_YWLX = ''
				}
			},
			activeIndexPRO(i, t, activeSub) {
				let SSType = i;
				uni.navigateTo({
					url: '/pages/public/search-pro?t=' + i
				})
			},
			activeIndexGS(i, Title, acindex) {
				activeIndex = acindex
				let SSType = i;
				uni.navigateTo({
					url: '/pages/public/search-gs?t=' + i + '&title=' + Title + '&Btype=' + this.outType[this
						.outTypeIndex].ItemValue
				})
			},

			mapSattionName(data) {
				if (!data) return [];
				let arr = JSON.parse(data);
				return arr;
			},

			getNote(e) {
				// console.log(e)
				VMEMO = e.target.value;
			},
			onConfirm(val) {
				if (activeIndex == 'M') {
					_self.mainOrder.NEXTPAIRDATE = val.result
				} else {
					this.checkData[activeIndex][dateTimekey] = val.result;
				}
			},
			dateEvent(id, index) {
				dateTimekey = id;
				activeIndex = index;
				this.$refs.dateTime.show();
			},
			activeIndexM(i, t) {
				_self.activeLineIndex = i;
				activeType = t;
				console.log('activeIndexM', i, t);
				let queryParames = "",
					pk_my_org = "";
				if (t == "BA_DEPARTMENT" ) {
					pk_my_org = this.mainOrder.PK_ORG;
				} else if (t == "BA_ORGANIZE") {
					pk_my_org = this.mainOrder.PK_GROUP;
				}else if(t  == 'EQBOM' ){
					queryParames =  { PK_MATERIAL : this.checkData[i].PK_MATERIAL } 
					queryParames =	JSON.stringify(queryParames)
					
					console.log(777, queryParames);
				}

				uni.navigateTo({
					url: "/pages/public/search?t=" +
						t +
						"&organizeId=" +
						pk_my_org +
						"&queryjson=" +
						queryParames
				});
			},
			activeNote() {
				_self.isActiveNote = true;
			},
			addItem() {
				uni.navigateBack({});
			},

			openScanMater() {
				let URL = this.userInfo.BaseURL + api.apiPublic.ScanCode;
				this.$utils.Scan(URL, item => {
					item.FACTORYDATE = item.FACTORYDATE ? item.FACTORYDATE : "";
					item.EXPDATE = item.EXPDATE ? item.EXPDATE : "";
					item.INSTOCKDATE = item.INSTOCKDATE ?
						item.INSTOCKDATE :
						_self.$utils.getToDay();
					item.TOTALNUM = item.TOTALNUM ? item.TOTALNUM : item.KCNUM;
					item.NNUM = 0;
					item.OUTPHOTO = item.OUTPHOTO ? item.OUTPHOTO : "";
					item.VBDEF20 = item.VBDEF20 ? item.VBDEF20 : 0;
					item.STORENAME = item.STORENAME ? item.STORENAME : "";
					item.PK_STORE = item.PK_STORE ? item.PK_STORE : "";
					item.STATIONNAME = item.STATIONNAME ? item.STATIONNAME : "";
					item.PK_STATION = item.PK_STATION ? item.PK_STATION : "";
					item.INPHOTO = item.INPHOTO ? item.INPHOTO : "";
					item.PURPOSE = item.PURPOSE ? item.PURPOSE : "";
					item.UNIT = item.UNIT ? item.UNIT : item.MINUNITNAME;
					item.myindex01 = item.myindex01 ? item.myindex01 : 0;

					_self.PushCheckData(item);
				});
			},

			openScan(id, index) {
				// _isActiveStore = true ;
				// console.log(id,index)
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						// console.log(res)
						if (res.scanType != "QR_CODE") {
							return uni.showToast({
								icon: "none",
								title: "类型错误，请重新扫描"
							});
						}
						let t = res.result.replace(/'/g, '"');
						let data = JSON.parse("{" + t + "}");
						let sid = "PK_" + id,
							sname = id + "NAME";
						if (id == "msid") {
							_self.mainOrder.PK_STORE = data.PK_STORE;
							_self.mainOrder.STORENAME = data.STORENAME;
						} else if (id == "STORE") {
							_self.planList[index][sname] = data.STORENAME;
							_self.planList[index][sid] = data.PK_STORE;
						} else if (id == "STATION") {
							_self.planList[index][sname] = data.STATIONNAME;
							_self.planList[index][sid] = data.PK_STATION;
						}
					}
				});
			},

			submit() {
				let data = {
					..._self.mainOrder,
					Detail: _self.checkData
				};
				// console.log(88, data);
				for (let i = 0; i < this.checkData.length; i++) {
					let item = this.checkData[i];
					if (item.NNUM == "0") {
						uni.showToast({
							title: `第${i + 1}个物资出库数量不能为0`,
							icon: "none",
							duration: 2000
						});
						return false;
					}
				}

				let URL = api.apiPublic.SaveOutApply;
				console.log(data);
				this.axios({
					url: URL,
					data: data,
					isLoading: 1,
				}).then(res => {
					_self.setCheckData([]);
					setTimeout(function() {
						_self.$utils.tips('提交成功')
					}, 100)
					setTimeout(() => {
						uni.$emit("refreshList");
						uni.navigateBack({});
					}, 1000);
				})
			},

			removeEvent(i) {
				let d = this.checkData[i].myIndex + "";
				if (this.checkData.length == 1) {
					return this.$utils.tips("最后一项不可删除");
				}
				this.deleteCheckData(i);
			},

			radioChange(v, i) {
				let val = v.detail.value
				_self.checkData[i].ISMEANS = val
			},
			
			handelScan(i){
				this.$utils.openScanUtils( i,i, (res)=>{
					if(res.includes('TYPE:8')){
						let arr = res.split('|')
						_self.checkData[i].EQUIPNAME = arr[1]
						_self.checkData[i].PK_EQUIP = arr[2]
					}
				})
			}
		}
	};
</script>

<style scoped>
	.card-wrapper {
		padding: 26upx;
	}

	.line-height-30 {
		line-height: 24px !important;
	}


	.sub-table-input {
		margin-top: 10upx;
	}

	.width60 {
		width: 60%;
	}

	.down-arrow-btn {
		top: -20upx;
		right: 0upx;
		font-size: 40upx;
		padding: 10upx;
	}

	.add-btn-wrap {
		position: fixed;
		bottom: 100upx;
		right: 50upx;
	}

	.add-btn-wrap .cuIcon-add {
		font-size: 50upx;
	}
</style>